﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}

@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@section header{
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/bootstrap.treetable/1.0/bootstrap-treetable.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/bootstrap.treetable/1.0/bootstrap-treetable.min.js"))
}

<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        地点名称：<input id="areaName" col="AreaName" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchTreeGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group-sm" id="toolbar">
            <a id="btnDelete" class="btn btn-danger" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">

    $(function () {

        initTreeGrid();

    });

    function initTreeGrid() {
        var options = {
            code: "AreaCode",
            parentCode: "ParentAreaCode",
            uniqueId: "Id",
            expandAll: false,
            expandFirst: false,
            toolbar: '#toolbar',
            expandColumn: '2',
            url: '@Url.Content("~/SystemManage/Area/GetListJson")',
            modalName: "行政区划",
            columns: [
                { field: 'Id', visible: false },
                { field: 'selectItem', radio: true },
                { field: 'AreaName', title: '地点名称', width: '50%' },
                { field: 'ZipCode', title: '邮政编码', width: '25%', align: "left" },
                { field: 'AreaLevel', title: '级别', width: '25%', align: "left" }
            ]
        };
        $('#gridTable').ysTreeTable(options);
    }

    function searchTreeGrid() {
        var param = $("#searchDiv").getWebControls();
        $('#gridTable').ysTreeTable('search', param);
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $("#gridTable").bootstrapTable("getSelections");
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? "编辑" : "添加",
            content: '@Url.Content("~/SystemManage/Area/AreaForm")' + '?id=' + id,
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteForm() {
        var selectedRow = $("#gridTable").bootstrapTable("getSelections");
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm("确认要删除选中的" + selectedRow.length + "条数据吗？", function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/SystemManage/Area/DeleteFormJson")' + '?ids=' + ids,
                    type: "post",
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }
</script>
